package com.itheima.util;

import java.util.Random;

public class CodeUtil {
    public CodeUtil(){

    }

    static char[] ziMu=new char[52];

    static {
        //存入字母
        for(int i=0;i<ziMu.length;i++){
            if(i<26){
                ziMu[i]=(char)(i+'a');
            }else {
                ziMu[i]=(char)(i-26+'A');
            }

        }
    }

    public static String getCode(){
        Random r=new Random();
        StringBuilder sb=new StringBuilder();
        //随机4个字母的索引并添加到sb
        for(int i=0;i<4;i++){
            int index = r.nextInt(52);
            sb.append(ziMu[index]);
        }
        //随机数字并随即插入
        int num = r.nextInt(10);
        sb.insert(r.nextInt(4),num);

        return sb.toString();
    }
}
